home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 19
/
CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso
/
CUCD
/
Online
/
Apache
/
cgi-bin
/
testform.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1997-06-11
|
2KB
|
83 lines
/* Parses test form */
options results
say "Content-Type: text/html"
say ""
getvar REQUEST_METHOD
method = result
getvar CONTENT_TYPE
type = result
getvar CONTENT_LENGTH
length = result
getvar QUERY_STRING
query = result
/* used on GET form queries */
if length(query) > 0 then do
/* go through the query string extracting name, value pairs */
do forever while length(query) > 0
parse var query name '=' value '&'
value = plus_to_space(unescape_url(value))
echo "<LI>name is " || name || ", value is " || value
/* advances query to the next name=value pair */
spot = index(query,"&")
if (spot ~= 0) then query = substr(query,index(query,"&")+1)
else query = ""
end
end
say "<UL>"
say "<LI> method is " || method
say "<LI> type is " || type
say "<LI> length is " || length
say "<LI> query is " || query
/* used on POST queries */
word = getword("")
do forever while word ~ = ""
parse var word name '=' value
say "<LI>name is " || name
say "value is " || value
word = getword("")
end
say "</ul>"
exit
/* used in POST queries, gets a name=value pair from stdin */
getword : procedure
retval = ""
do forever while (eof(stdin) = 0)
ch = readch(stdin,1)
if ch = -1 then leav e
if ch = '&' then leave
retval = retval || ch
end
return unescape_url(plus_to_space(retval))
/* Converts the "+" in the url to spaces */
plus_to_space : procedure
ARG url
return translate(url, " ", "+")
/* change %xx to the ascii equivalent - eg %20 is a space */
unescape_url : procedure
ARG url
retval = ""
do i = 1 to length(url)
chr = substr(url,i,1)
if chr = '%' then do
chr = substr(url,i+1,2);
newchr = x2c(chr)
retval = retval || newchr
i = i + 2
end
else retval = retval || chr
end
return retval